import 'package:aio/aio.dart';
import 'package:app/src/utils/unit_utils.dart';
import 'package:flutter/material.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/bean/clockin/attendances.dart';
import 'package:app/src/http/bean/http_data.dart';

import '../../../manager/ywx_manager.dart';
import '../works_2023/purcontract_bean.dart';
import '../wroks/contract_bean.dart';
import '../wroks/search_bean.dart';
import '../ywx_limit.dart';
import 'package:decimal/decimal.dart';

///物料种类；品牌搜索条件
class PreSearchMaterialInfo extends BaseBean {
  static String Type_MaterialType = "MaterialType"; //物料种类
  static String Type_ProjectName = "ProjectName"; //工程名称
  static String Type_ManufacturerName = "ManufacturerName"; //品牌名称
  static String Type_GetAllManufacturer =
      "GetAllManufacturer"; //全部品牌;（已生成里面的获取品牌方法,只在已生成里面使用）
  static String Type_Creater = "GetPurDemandCreater"; //创建人

  ///获取品牌名称Type
  static String getTypeWithManufacturer(String? ReviewType2) {
    if (ReviewType.MaterialRequisition_OriginalRequisition == ReviewType2) {
      //原片请购
      return Type_ManufacturerName;
    } else if (ReviewType.MaterialRequisition_AccessoriesRequisition ==
        ReviewType2) {
      //辅料请购
      return Type_ManufacturerName;
    } else if (ReviewType.MaterialRequisition_HardwareRequisition ==
        ReviewType2) {
      //五金请购
      return Type_ManufacturerName;
    }
    return Type_GetAllManufacturer; //已生成；全部品牌（只在已生成里面使用）
  }

  String type =
      Type_MaterialType; //接口请求类型 MaterialType（物料种类）；ProjectName(工程名称);ManufacturerName(品牌名称)

  /// 物料类型  MT01：原片 MT02：辅料 MT03：五金
  String? MaterialType = "";

  /// 物料类型主键(搜索品牌时，可能需要)
  String? MaterialTypeId = "";
  String KeyWord = ""; //搜索关键字

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    MaterialType = json["MaterialType"]?.toString() ?? "";
    type = json["type"]?.toString() ?? "";
    KeyWord = json["KeyWord"]?.toString() ?? "";
    MaterialTypeId = json["MaterialTypeId"]?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return PreSearchMaterialInfo();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["MaterialType"] = MaterialType;
    map["type"] = type;
    map["KeyWord"] = KeyWord;
    map["MaterialTypeId"] = MaterialTypeId;
    return map;
  }
}

///物料请购搜索数据
class SearchMaterialInfo extends BaseBean {
  /// 工厂
  String? FactoryId = "";
  String? FactoryName = "";

  //种类，如:原片种类，辅料种类，五金种类
  String? SpeciesId = "";
  String? SpeciesName = "";

  /// 物料名称
  String? MaterialName = "";

  /// 品牌Id
  String? ManufacturerId = "";

  /// 品牌名称
  String? ManufacturerName = "";

  /// 物料类型  MT01：原片 MT02：辅料 MT03：五金
  String? MaterialType = "";

  /// 请购单号
  String? PurCode = "";

  /// 项目名称
  String? ProjectName = "";

  /// 创建人
  String? Creater = "";
  String? CreaterId = "";

  ///采购要货日期(开始)
  String? PurStartDate = "";

  ///采购要货日期(结束)
  String? PurEndDate = "";

  String? State = ""; //状态

  SearchMaterialInfo() {}

  SearchMaterialInfo.fromSerch(SearchInfo? searchInfo) {
    // print(
    //     "搜索条件：==============================================${searchInfo}\t${searchInfo?.isDelFactory}\t${searchInfo?.factory}");
    FactoryId = searchInfo?.factory?.FactoryId ?? "";
    FactoryName = searchInfo?.factory?.FactoryName ?? "";
    SpeciesId = searchInfo?.Species?.Id ?? "";
    SpeciesName = searchInfo?.Species?.Name ?? "";
    MaterialName = searchInfo?.MaterialName ?? "";
    ManufacturerId = searchInfo?.Brand?.Id ?? "";
    ManufacturerName = searchInfo?.Brand?.Name ?? "";
    MaterialType = searchInfo?.TypeOfMaterial?.key ?? "";
    PurCode = searchInfo?.PurchaseOrderNumber ?? "";
    ProjectName = searchInfo?.ProjectName ?? "";
    Creater = searchInfo?.FounderName ?? "";
    CreaterId = searchInfo?.FounderId ?? "";
    PurStartDate = searchInfo?.InsertStartDatetime ?? "";
    PurEndDate = searchInfo?.InsertEndDatetime ?? "";
    State = searchInfo?.PurchaseStatus?.key ?? "";
  }

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    FactoryId = json["FactoryId"]?.toString() ?? "";
    FactoryName = json["FactoryName"]?.toString() ?? "";
    SpeciesId = json["SpeciesId"]?.toString() ?? "";
    SpeciesName = json["SpeciesName"]?.toString() ?? "";
    MaterialName = json["MaterialName"]?.toString() ?? "";
    ManufacturerId = json["ManufacturerId"]?.toString() ?? "";
    ManufacturerName = json["ManufacturerName"]?.toString() ?? "";
    MaterialType = json["MaterialType"]?.toString() ?? "";
    PurCode = json["PurCode"]?.toString() ?? "";
    ProjectName = json["ProjectName"]?.toString() ?? "";
    Creater = json["Creater"]?.toString() ?? "";
    CreaterId = json["CreaterId"]?.toString() ?? "";
    PurStartDate = json["PurStartDate"]?.toString() ?? "";
    PurEndDate = json["PurEndDate"]?.toString() ?? "";
    State = json["State"]?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return SearchMaterialInfo();
  }

  @override
  Map<String, dynamic> toJson() {
    var map = <String, dynamic>{};
    map["FactoryId"] = FactoryId;
    map["FactoryName"] = FactoryName;
    map["SpeciesId"] = SpeciesId;
    map["SpeciesName"] = SpeciesName;
    map["MaterialName"] = MaterialName;
    map["ManufacturerId"] = ManufacturerId;
    map["ManufacturerName"] = ManufacturerName;
    map["MaterialType"] = MaterialType;
    map["PurCode"] = PurCode;
    map["ProjectName"] = ProjectName;
    map["Creater"] = Creater;
    map["CreaterId"] = CreaterId;
    map["PurStartDate"] = PurStartDate;
    map["PurEndDate"] = PurEndDate;
    map["State"] = State;
    return map;
  }
}

///物料请购
class MaterialInfo extends GetPurOrder {
  ///原片请购，辅料请购，五金请购
  // String? Id = ""; //主键ID
  // String? MaterialName = ""; //物料名称，如：原片名称，辅料名称，五金名称
  // String? MaterialCode = ""; //物料编码
  // String? Brand = ""; //品牌
  // String? Specifications = ""; //规格
  // String? InventoryNum = ""; //库存数量
  // String? InventoryArea = ""; //库存面积，只有原片有，辅料，五金没有。
  ///已生成
  // String? PurchaseOrder = ""; //请购单号
  // String? MaterialType = ""; //物料类型
  // String? ProjectName = ""; //项目名称
  // String? Founder = ""; //创建人
  // String? DateRequest = ""; //请购日期
  // String? DatePurchase = ""; //请购要货日期
  // DateTime? DatePurchaseDateTime = null;
  String? state = ""; //状态
  String? ywxName = ""; //当前流程
  bool isModify = false; //true 修改，false 查看。

  ///判断是否可操作。
  bool isCanoOeration() {
    if (isModify) {
      return true; //修改，可操作。
    } else if (StringUtils.isEmpty(PurCode)) {
      return true; //请购单号为空。申请采购可以操作。
    }
    return false; //不能做任何操作；只能查看。
  }

  ///详情页面只有返回键
  bool isOnlyBack() {
    if (isCanoOeration()) {
      return false;
    } else {
      return true; //不能操作(只能查看)，就只有返回键。
    }
  }

  ///获取唯一标致
  String getId() {
    return "$Id$PurCode$CreaterName$CreaterId";
  }

  //创建人 ，常浩东
  String? CreaterName = "";

  String CreaterId = "";

  ///CreaterIdOld 自己创建的，记录
  String CreaterIdOld = "";
  String PersonId = "";

  String DeptId = "";

  String? Status = "";

  ///状态名称
  String? StatusName = "";

  /// 主键Id
  String? Id = "";

  /// 请购单号
  String? PurCode = "";

  /// 工厂
  String? FactoryId = "";
  String? FactoryName = "";

  var _facory = Factory();

  Factory getFactory() {
    _facory.FactoryId = FactoryId ?? "";
    _facory.key = _facory.FactoryId;
    _facory.FactoryName = FactoryName ?? "";
    _facory.value = _facory.FactoryName;
    return _facory;
  }

  ///判断工厂是否为空。
  bool isEmptyFactory() {
    if (StringUtils.isEmpty(FactoryName)) {
      if (StringUtils.isEmpty(FactoryId) || "0" == FactoryId) {
        return true;
      }
    }
    return false;
  }

  /// 合同
  String? SContractCode = "";

  /// 项目id
  String? ProjectId = "";

  /// 项目名称
  String? ProjectName = "";

  /// 采购开始时间（请购日期）
  String? PurStartDate = "";

  String getPurStartDate() {
    if (StringUtils.isEmpty(PurStartDate)) {
      PurStartDate = DateTimeUtils.getDateTimeFormat(); //默认显示当前日期
    }
    if (PurStartDate != null && PurStartDate!.contains(" ")) {
      return PurStartDate!.split(" ")[0];
    }
    return PurStartDate ?? "";
  }

  // "PurStartDate": "2022-12-20T00:00:00",
  // "PurEndDate": "2022-12-31T00:00:00",
  // "PurStartDate": "0001-01-01T00:00:00",
  // "PurEndDate": "0001-01-01T00:00:00",
  /// 采购结束时间(请购要货日期)
  String? PurEndDate = "";

  String getPurEndDate2() {
    if (PurEndDate != null && PurEndDate!.contains(" ")) {
      return PurEndDate!.split(" ")[0];
    }
    return PurEndDate ?? "";
  }

  String? getPurEndDate() {
    return PurEndDate?.replaceAll("00:00:00", "");
  }

  DateTime? PurEndDateTime = null;

  DateTime? getPurEndDateTime() {
    if (PurEndDateTime == null && StringUtils.isNotEmpty(PurEndDate)) {
      try {
        PurEndDateTime = DateTime.parse(PurEndDate!);
      } catch (e) {
        print("采购结束时间(请购要货日期)异常：$e");
      }
    }
    return PurEndDateTime;
  }

  int? inDays = null;

  ///超期多少天；
  int distancePurEndDateTime() {
    if (inDays != null) {
      return inDays!;
    }
    DateTime? pur = getPurEndDateTime();
    if (pur != null) {
      DateTime now = DateTime.now();
      var difference = now.difference(pur); //前面的和后面的比较（前面的-后面的）；（正数d7大，负数d7小。）
      inDays = difference.inDays;
      return inDays!;
    }
    return 0;
  }

  /// 创建人(和CreaterId一样，都是创建人id)
  String? Creater = "";

  /// 区分采购计划来源
  String? PlanType = "";

  /// 是否绑定
  bool IsBind = false;

  String getBind(BuildContext context) {
    if (IsBind) {
      return AppStrings.of(context).Yes;
    }
    return AppStrings.of(context).No;
  }

  /// 备注
  String? BeiZhu = "";

  /// 供应商
  String? SupplierId = "";

  /// 供应商
  String? SupplierName = "";

  // [
  // "/UploadFile/PurchaseFile/20230202120451/b8389b504fc2d56280256536e61190ef76c66c3f.jpg,b8389b504fc2d56280256536e61190ef76c66c3f.jpg,106155,jpg,PurchasePicker"
  // ]
  //格式：“图片地址,图片名称,大小,后缀, ”
  ///文件路径（服务器的）
  List<String>? FilePatch = null;

  ///文件路径，保存服务器原始的。
  List<String>? FilePatchOld = null;

  ///files 上传的文件
  setFiles(List<String>? files) {
    if (FilePatch == null) {
      FilePatch = [];
    }
    // print(
    //     "===============================================FilePatchOld:$FilePatchOld");
    FilePatch?.clear();
    // print(
    //     "===============================================FilePatchOld:$FilePatchOld");
    if (FilePatchOld != null && FilePatchOld!.length > 0) {
      FilePatch?.addAll(FilePatchOld!);
      // print(
      //     "===============================================FilePatch:$FilePatch");
    }
    if (files != null && files!.length > 0) {
      //FilePatch?.addAll(files);
      files.forEach((element) {
        var fileName = FileUtils.getFileName(element, suffix: true); //文件名
        var size = "1"; //文件大小
        var Suffix = FileUtils.getFileSuffix(element, hasPoint: false); //文件后缀
        var PurchasePicker = "";
        var str = "$element,$fileName,$size,$Suffix,$PurchasePicker";
        FilePatch?.add(str);
      });
    }
    // FilePatch?.forEach((element) {
    //   print(
    //       "===============================================element:$element");
    // });
  }

  //物料信息
  List<PurDemand>? PurDemandList = null;

  ///审核日志
  List<WFLog>? WFLogList = null;

  String? IsSave = "0"; //0 保存，1提交。

  //设置物料请购状态
  setSave(String s) {
    //print("状态码：\t$s");
    if (s == "0") {
      isSave(true);
    } else {
      isSave(false);
    }
  }

  ///物料请求，保存，提交。
  isSave(bool b) {
    if (b) {
      IsSave = "0"; //保存
    } else {
      IsSave = "1"; //提交
    }
  }

  ///显示按钮名称
  String getShowStateName(BuildContext context, YwxItem? item) {
    if (item?.ReviewType == ReviewType.TicketCenter &&
        AppStrings.of(context).Ticket_center == item?.YwxName) {
      //工单中心
      return AppStrings.of(context).Sendorders; //派单
    } else if (item?.ReviewType == ReviewType.Myworkorder &&
        AppStrings.of(context).Myworkorder == item?.YwxName) {
      //我的工单
      return AppStrings.of(context).ToView; //查看
    } else if (item?.ReviewType2 ==
        ReviewType.MaterialRequisition_OriginalRequisition) {
      //原片请购
      return AppStrings.of(context).Applicationforpurchase; //申请采购
    } else if (item?.ReviewType2 ==
        ReviewType.MaterialRequisition_AccessoriesRequisition) {
      //辅料请购
      return AppStrings.of(context).Applicationforpurchase; //申请采购
    } else if (item?.ReviewType2 ==
        ReviewType.MaterialRequisition_HardwareRequisition) {
      //五金请购
      return AppStrings.of(context).Applicationforpurchase; //申请采购
    } else if (item?.ReviewType2 == ReviewType.MaterialRequisition_Generated) {
      //物料请购：已生成
      if (isModify) {
        return AppStrings.of(context).Modifythe; //修改
      }
    }
    return AppStrings.of(context).ToView; //查看
  }

  String? wfId = ""; //撤回时使用。
  bool recall = false; //已审核里，是否显示撤回按钮
  String? NextNode = ""; //采购审核，为空没有流程节点直接审批

  String? OriginApproveNum = ""; //原批准数量
  String? ApproveNum = ""; //批准数量
  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    super.fromJson(json); //fixme 先调父类
    state = json["state"]?.toString() ?? "";
    ywxName = json["ywxName"]?.toString() ?? "";
    var isModify2 = json["isModify"]?.toString() ?? "";
    if (isModify2 == "true") {
      isModify = true;
    } else {
      isModify = false;
    }
    Id = json["Id"]?.toString() ?? "";
    PurCode = json["PurCode"]?.toString() ?? "";
    FactoryId = json["FactoryId"]?.toString() ?? "";
    FactoryName = json["FactoryName"]?.toString() ?? "";
    SContractCode = json["SContractCode"]?.toString() ?? "";
    ProjectId = json["ProjectId"]?.toString() ?? "";
    ProjectName = json["ProjectName"]?.toString() ?? "";
    PurStartDate = json["PurStartDate"]?.toString() ?? "";
    PurEndDate = json["PurEndDate"]?.toString() ?? "";
    Creater = json["Creater"]?.toString() ?? "";
    PlanType = json["PlanType"]?.toString() ?? "";
    var IsBind2 = json["IsBind"]?.toString() ?? "";
    if (IsBind2 == "true") {
      IsBind = true;
    } else {
      IsBind = false;
    }
    BeiZhu = json["BeiZhu"]?.toString() ?? "";
    SupplierId = json["SupplierId"]?.toString() ?? "";
    SupplierName = json["SupplierName"]?.toString() ?? "";
    FilePatch = setGenericFromJson(json, "FilePatch", <String>[], "");
    if (FilePatch == null) {
      FilePatch = [];
    }
    // FilePatchOld = FilePatch; //记录服务器原始的文件路径;fixme 不要直接赋值，这样会变成一个对象。
    FilePatchOld = [];
    FilePatch?.forEach((element) {
      FilePatchOld?.add(element); //fixme 新建对象，直接赋值。
    });
    PurDemandList =
        setGenericFromJson(json, "PurDemandList", <PurDemand>[], PurDemand());
    WFLogList = setGenericFromJson(json, "WFLogList", <WFLog>[], WFLog());
    if (WFLogList == null) {
      WFLogList = [];
    }
    CreaterName = json["CreaterName"]?.toString() ?? "";
    CreaterId = json["CreaterId"]?.toString() ?? "";
    CreaterIdOld = CreaterId;
    PersonId = json["PersonId"]?.toString() ?? "";
    DeptId = json["DeptId"]?.toString() ?? "";
    Status = json["Status"]?.toString() ?? "";
    StatusName = json["StatusName"]?.toString() ?? "";
    IsSave = json["IsSave"]?.toString() ?? "";
    wfId = json["wfId"]?.toString() ?? "";
    var rc = json["recall"]?.toString().toLowerCase();
    if (rc == "true") {
      recall = true;
    } else {
      recall = false;
    }
    NextNode = json["NextNode"]?.toString() ?? "";
    OriginApproveNum = json["OriginApproveNum"]?.toString() ?? "";
    ApproveNum = json["OriginApproveNum"]?.toString() ??
        ""; //fixme 批准数量，默认值就是原批准数量OriginApproveNum
  }

  @override
  instance() {
    // TODO: implement instance
    return MaterialInfo();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    // var map = <String, dynamic>{};
    var map = super.toJson(); //fixme 先调父类
    // ///原片请购，辅料请购，五金请购
    // map["Id"] = Id;
    // map["MaterialName"] = MaterialName;
    // map["MaterialCode"] = MaterialCode;
    // map["Brand"] = Brand;
    // map["Specifications"] = Specifications;
    // map["InventoryNum"] = InventoryNum;
    // map["InventoryArea"] = InventoryArea;
    //
    // ///已生成
    // map["PurchaseOrder"] = PurchaseOrder;
    // map["MaterialType"] = MaterialType;
    // map["ProjectName"] = ProjectName;
    // map["Founder"] = Founder;
    // map["DateRequest"] = DateRequest;
    // map["DatePurchase"] = DatePurchase;
    map["state"] = state;
    map["ywxName"] = ywxName;
    map["isModify"] = isModify;
    map["Id"] = Id;
    map["PurCode"] = PurCode;
    map["FactoryId"] = FactoryId;
    map["FactoryName"] = FactoryName;
    map["SContractCode"] = SContractCode;
    map["ProjectId"] = ProjectId;
    map["ProjectName"] = ProjectName;
    map["PurStartDate"] = PurStartDate;
    map["PurEndDate"] = PurEndDate;
    map["Creater"] = Creater;
    map["PlanType"] = PlanType;
    map["IsBind"] = IsBind;
    map["BeiZhu"] = BeiZhu;
    map["SupplierId"] = SupplierId;
    map["SupplierName"] = SupplierName;
    map["FilePatch"] = FilePatch;
    map["PurDemandList"] = PurDemandList;
    map["WFLogList"] = WFLogList;
    map["CreaterName"] = CreaterName;
    map["CreaterId"] = CreaterId;
    map["PersonId"] = PersonId;
    map["DeptId"] = DeptId;
    map["Status"] = Status;
    map["StatusName"] = StatusName;
    map["IsSave"] = IsSave;
    map["wfId"] = wfId;
    map["recall"] = recall;
    map["NextNode"] = NextNode;
    map["OriginApproveNum"] = OriginApproveNum;
    map["ApproveNum"] = ApproveNum;
    return map;
  }

  MaterialInfo();

  MaterialInfo.all(
      this.state,
      this.ywxName,
      this.isModify,
      this.CreaterName,
      this.CreaterId,
      this.CreaterIdOld,
      this.PersonId,
      this.DeptId,
      this.Status,
      this.StatusName,
      this.Id,
      this.PurCode,
      this.FactoryId,
      this.FactoryName,
      this.SContractCode,
      this.ProjectId,
      this.ProjectName,
      this.PurStartDate,
      this.PurEndDate,
      this.PurEndDateTime,
      this.Creater,
      this.PlanType,
      this.IsBind,
      this.BeiZhu,
      this.SupplierId,
      this.SupplierName,
      this.FilePatch,
      this.FilePatchOld,
      this.PurDemandList,
      this.WFLogList,
      this.IsSave,
      this.wfId,
      this.NextNode,
      this.OriginApproveNum,
      this.ApproveNum);

  MaterialInfo copy() {
    var materialInfo = MaterialInfo.all(
        state,
        ywxName,
        isModify,
        CreaterName,
        CreaterId,
        CreaterIdOld,
        PersonId,
        DeptId,
        Status,
        StatusName,
        Id,
        PurCode,
        FactoryId,
        FactoryName,
        SContractCode,
        ProjectId,
        ProjectName,
        PurStartDate,
        PurEndDate,
        PurEndDateTime,
        Creater,
        PlanType,
        IsBind,
        BeiZhu,
        SupplierId,
        SupplierName,
        FilePatch,
        FilePatchOld,
        PurDemandList,
        WFLogList,
        IsSave,
        wfId,
        NextNode,
        OriginApproveNum,
        ApproveNum);
    List<PurDemand>? mPurDemandList = null;
    if (materialInfo.PurDemandList != null &&
        materialInfo.PurDemandList!.length > 0) {
      mPurDemandList = [];
      materialInfo.PurDemandList?.forEach((element) {
        mPurDemandList?.add(element.copy());
      });
    }
    materialInfo.PurDemandList = mPurDemandList;
    return materialInfo;
  }
}

class PurDemand extends BaseBean {
  @override
  instance() {
    return PurDemand();
  }

  PurDemand();

  PurDemand.all(
      this.ListId,
      this.MaterialType,
      this.MaterialTypeId,
      this.MaterialCode,
      this.MaterialName,
      this.Width,
      this.Height,
      this.Thickness,
      this.Lengths,
      this.Numbers,
      this.Isquantity,
      this.Iswidth,
      this.Isheight,
      this.Isthickness,
      this.Islength,
      this.CanWrite,
      this.Size,
      this.DemandNum,
      this.MinNum,
      this.MainUnit,
      this.SubsidiaryNum,
      this.SubsidiaryUnit,
      this.ManufacturerId,
      this.ManufacturerName,
      this.StockNum,
      this.StockArea,
      this.ProductId,
      this.SourceType,
      this.FactoryId,
      this.FactoryName,
      this.OriginApproveNum,
      this.ApproveNum,
      this.ApplyNum,
      this.MaterialTypeCode,
      this.ListBeizhu,
      this.index,
      this.PackageUnit,
      this.WidthUnit,
      this.HeightUnit,
      this.LengthUnit,
      this.ThicknessUnit,
      this.PackageCount,
      this.PackageListCount,
      this.QuantityUnit);

  ///新加字段；
  String? PackageUnit = ""; //包的单位
  String? WidthUnit = ""; //宽单位
  String? HeightUnit = ""; //高单位
  String? LengthUnit = ""; //长单位
  String? ThicknessUnit = ""; //厚度单位
  String? PackageCount = ""; //包数量
  String? PackageListCount = ""; //每包数量
  ///判断包数量是否为空或0
  bool isEmptyPackageCount() {
    if (StringUtils.isEmpty(PackageCount)) {
      return true;
    } else {
      try {
        var d = double.parse(PackageCount!);
        if (d <= 0) {
          return true;
        }
      } catch (e) {}
    }
    return false;
  }

  ///判断每包数量是否为空或0
  bool isEmptyPackageListCount() {
    if (StringUtils.isEmpty(PackageListCount)) {
      return true;
    } else {
      try {
        var d = double.parse(PackageListCount!);
        if (d <= 0) {
          return true;
        }
      } catch (e) {}
    }
    return false;
  }

  PurDemand copy() {
    var purDemand = PurDemand.all(
        ListId,
        MaterialType,
        MaterialTypeId,
        MaterialCode,
        MaterialName,
        Width,
        Height,
        Thickness,
        Lengths,
        Numbers,
        Isquantity,
        Iswidth,
        Isheight,
        Isthickness,
        Islength,
        CanWrite,
        Size,
        DemandNum,
        MinNum,
        MainUnit,
        SubsidiaryNum,
        SubsidiaryUnit,
        ManufacturerId,
        ManufacturerName,
        StockNum,
        StockArea,
        ProductId,
        SourceType,
        FactoryId,
        FactoryName,
        OriginApproveNum,
        ApproveNum,
        ApplyNum,
        MaterialTypeCode,
        ListBeizhu,
        index,
        PackageUnit,
        WidthUnit,
        HeightUnit,
        LengthUnit,
        ThicknessUnit,
        PackageCount,
        PackageListCount,
        QuantityUnit);
    purDemand.isCopy = true;
    return purDemand;
  }

  static String MT01 = "MT01"; //原片
  static String MT02 = "MT02"; //辅料
  static String MT03 = "MT03"; //五金

  ///获取当前物料请购物料类型
  static String getMaterialTypeWith(String? ReviewType2) {
    if (ReviewType.MaterialRequisition_OriginalRequisition == ReviewType2) {
      //原片请购
      return MT01;
    } else if (ReviewType.MaterialRequisition_AccessoriesRequisition ==
        ReviewType2) {
      //辅料请购
      return MT02;
    } else if (ReviewType.MaterialRequisition_HardwareRequisition ==
        ReviewType2) {
      //五金请购
      return MT03;
    }
    return ""; //已生成；传空。
  }

  int index = 0; //fixme 自己加的，用于表示序号。服务器需要

  String? ListBeizhu = ""; //备注

  bool isCopy = false; //是否为赋值数据

  /// 主键Id
  String? ListId = "";

  /// 物料类型  MT01：原片 MT02：辅料 MT03：五金
  String? MaterialType = "";

  String? MaterialTypeCode = "";

  /// 工厂
  String? FactoryId = "";
  String? FactoryName = "";

  String getMaterialTypeName(BuildContext context) {
    if (MaterialType == "MT01") {
      return AppStrings.of(context).Raw; //原片
    } else if (MaterialType == "MT02") {
      return AppStrings.of(context).SupplementaryMaterial; //辅料
    } else if (MaterialType == "MT03") {
      return AppStrings.of(context).Hardware; //五金
    }
    return "";
  }

  ///判断是否为原片
  bool isMT01() {
    if (MaterialType == MT01) {
      return true;
    }
    return false;
  }

  ///判断是否为辅料
  bool isMT02() {
    if (MaterialType == MT02) {
      return true;
    }
    return false;
  }

  /// 物料类型主键
  String? MaterialTypeId = "";

  bool isFirstMaterialCode = true; //判断是否为首次加载,自己定义的判断字段。
  /// 物料编码
  String? MaterialCode = "";

  /// 物料名称
  String? MaterialName = "";

  double toDouble(String? num) {
    if (StringUtils.isEmpty(num)) {
      return 1;
    } else {
      try {
        var d = double.parse(num!);
        if (d <= 0) {
          return 1; //小于等于0的作1处理。
        }
        return d;
      } catch (e) {}
    }
    return 1;
  }

  /// 宽;
  String? Width = "";

  double Width2() {
    var num = Width ?? "1";
    return toDouble(num);
  }

  ///判断宽是否为空或0
  bool isEmptyWidth() {
    if (StringUtils.isEmpty(Width)) {
      return true;
    } else {
      try {
        var d = double.parse(Width!);
        if (d <= 0) {
          return true;
        }
      } catch (e) {}
    }
    return false;
  }

  String? WidthInput = ""; //记录手动输入的。(自己加的本地参数)
  ///获取宽；
  String? getWidthInput() {
    if (StringUtils.isEmpty(WidthInput)) {
      //Width:============================0.0
      //print("Width:============================${Width}");
      //fixme 毫米转化为其他对应的单位；服务器默认传递的都是毫米。最后我们提交的时候，还需要再转化为毫米再提交给服务器。
      if (StringUtils.isEmpty(Width) || Width == "0" || Width == "0.0") {
        WidthInput = "0";
      } else {
        WidthInput =
            AppUnitUtils.mmtoUnit(WidthUnit, Width2().toString()).toString();
        WidthInput = StringUtils.toStringAsDecimal(WidthInput);
      }
    }
    return WidthInput;
  }

  /// 高
  String? Height = "";

  double Height2() {
    var num = Height ?? "1";
    return toDouble(num);
  }

  ///判断高是否为空或0
  bool isEmptyHeight() {
    if (StringUtils.isEmpty(Height)) {
      return true;
    } else {
      try {
        var d = double.parse(Height!);
        if (d <= 0) {
          return true;
        }
      } catch (e) {}
    }
    return false;
  }

  String? HeightInput = ""; //记录手动输入的。(自己加的本地参数)
  ///获取高；
  String? getHeightInput() {
    if (StringUtils.isEmpty(HeightInput)) {
      //毫米转化为其他对应的单位；服务器默认传递的都是毫米。
      if (StringUtils.isEmpty(Height) || Height == "0" || Height == "0.0") {
        HeightInput = "0";
      } else {
        HeightInput =
            AppUnitUtils.mmtoUnit(HeightUnit, Height2().toString()).toString();
        HeightInput = StringUtils.toStringAsDecimal(HeightInput);
      }
    }
    return HeightInput;
  }

  /// 长
  String? Lengths = "";

  double Lengths2() {
    var num = Lengths ?? "1";
    return toDouble(num);
  }

  ///判断长是否为空或0
  bool isEmptyLengths() {
    if (StringUtils.isEmpty(Lengths)) {
      return true;
    } else {
      try {
        var d = double.parse(Lengths!);
        if (d <= 0) {
          return true;
        }
      } catch (e) {}
    }
    return false;
  }

  String? LengthsInput = ""; //记录手动输入的。(自己加的本地参数)
  ///获取长；
  String? getLengthsInput() {
    if (StringUtils.isEmpty(LengthsInput)) {
      //毫米转化为其他对应的单位；服务器默认传递的都是毫米。
      if (StringUtils.isEmpty(Lengths) || Lengths == "0" || Lengths == "0.0") {
        LengthsInput = "0";
      } else {
        LengthsInput =
            AppUnitUtils.mmtoUnit(LengthUnit, Lengths2().toString()).toString();
        LengthsInput = StringUtils.toStringAsDecimal(LengthsInput);
      }
    }
    return LengthsInput;
  }

  /// 厚
  String? Thickness = "";

  double Thickness2() {
    var num = Thickness ?? "1";
    return toDouble(num);
  }

  ///判断厚是否为空或0
  bool isEmptyThickness() {
    if (StringUtils.isEmpty(Thickness)) {
      return true;
    } else {
      try {
        var d = double.parse(Thickness!);
        if (d <= 0) {
          return true;
        }
      } catch (e) {}
    }
    return false;
  }

  String? ThicknessInput = ""; //记录手动输入的。(自己加的本地参数)
  ///获取厚；
  String? getThicknessInput() {
    if (StringUtils.isEmpty(ThicknessInput)) {
      //毫米转化为其他对应的单位；服务器默认传递的都是毫米。
      if (StringUtils.isEmpty(Thickness) ||
          Thickness == "0" ||
          Thickness == "0.0") {
        ThicknessInput = "0";
      } else {
        ThicknessInput =
            AppUnitUtils.mmtoUnit(ThicknessUnit, Thickness2().toString())
                .toString();
        ThicknessInput = StringUtils.toStringAsDecimal(ThicknessInput);
      }
    }
    return ThicknessInput;
  }

  /// 数量
  String? Numbers = "";

  ///判断数量是否为空或0
  bool isEmptyNumbers() {
    if (StringUtils.isEmpty(Numbers)) {
      return true;
    } else {
      try {
        var d = double.parse(Numbers!);
        if (d <= 0) {
          return true;
        }
      } catch (e) {}
    }
    return false;
  }

  //数量单位
  String? QuantityUnit = "";

  ///获取数量，并且带单位。
  String? getNumbersStrAndUnit() {
    // return "${AppUnitUtils.getStringAs0(Numbers)}${QuantityUnit}";
    return "${StringUtils.toStringAsDecimal(Numbers)}${QuantityUnit}";
  }

  double Numbers2() {
    var num = Numbers ?? "1";
    return toDouble(num);
  }

  ///原片：只显示宽高；并且可以手填。
  ///辅料，五金；长，宽，高，厚，数量。都显示。
  ///fixme 以下的IS显示；是判断是否可以手动输入；

  /// 是否显示数量(是否可以手填)
  bool Isquantity = true;

  ///是否显示数量
  bool Isquantity2() {
    if (Isquantity) {
      return true;
    } else if (!isMT01()) {
      return true;
    }
    return false;
  }

  /// 是否显示宽(是否可以手填)
  bool Iswidth = true;

  /// 是否显示宽
  bool Iswidth2() {
    return true;
  }

  /// 是否显示高(是否可以手填)
  bool Isheight = true;

  /// 是否显示高
  bool Isheight2() {
    return true;
  }

  /// 是否显示厚(是否可以手填)
  bool Isthickness = true;

  /// 是否显示厚
  bool Isthickness2() {
    if (Isthickness) {
      return true;
    } else if (!isMT01()) {
      return true;
    }
    return false;
  }

  /// 是否显示长(是否可以手填)
  bool Islength = true;

  /// 是否显示长
  bool Islength2() {
    if (Islength) {
      return true;
    } else if (!isMT01()) {
      return true;
    }
    return false;
  }

  /// 是否可以手写品牌；如果为true 表示可以手动输入系统不存在的品牌；false 不能手输，只能选择系统已存在的。
  bool CanWrite = true;

  /// 规格型号
  String? Size = "";

  ///规格是否可操作；true 可填写；false 不可填写
  bool isOperationSize() {
    if (MaterialType == MT01) {
      return false; //原片，规格通过高和宽计算，不需要手填。
    }
    return true;
  }

  /// 需采购数量(申请数量)；虚采购数量。
  String? DemandNum = "";

  ///fixme 根据填入的规格，自动计算申请数量。
  ///isDemandNumUpdate 是否根据规格，自动计算。
  ///isPackageCount 包数量等于1；每包数量，自动等于申请数量。
  void autoDemandNum(bool isDemandNumUpdate, {bool isPackageCount = true}) {
    PurDemand? data = this;
    if (data != null && !data!.isMT01() && isDemandNumUpdate) {
      ///fixme 非原片类型；申请数量可以手动计算
      int count = 0;
      if (data.Iswidth) {
        count++;
      }
      if (data.Isheight) {
        count++;
      }
      if (data.Islength) {
        count++;
      }
      if (data.Isthickness) {
        count++;
      }
      //fixme 计算申请数量
      if (count > 0) {
        try {
          //fixme 旧的计算。
          // double n = 1000;
          // if (count == 1) {
          //   n = 1000;
          // } else if (count == 2) {
          //   n = 1000000;
          // } else if (count == 3 || count == 4) {
          //   n = 1000000000;
          // }
          // var applyNum = ((((data.Width2() *
          //             data.Height2() *
          //             data.Lengths2() *
          //             data.Thickness2()) /
          //         n) *
          //     data.Numbers2())); //长宽高
          // print(
          //     "count:${count}\tWidth2:${data.Width2()}\tHeight2:${data.Height2()}\tLengths2:${data.Lengths2()}\tThickness2:${data.Thickness2()}\tn:${n}\tNumbers2:${data.Numbers2()}\tapplyNum:$applyNum");

          ///fixme 新的计算方式
          double? _width = data.Width2().toDouble(); //宽
          double? _height = data.Height2().toDouble(); //高
          double? _lengths = data.Lengths2().toDouble(); //长
          double? _thickness = data.Thickness2().toDouble(); //厚
          double? _numbers = data.Numbers2().toDouble(); //数量
          double baseUnit = 1000; //1米等于1000毫米。
          bool isAll0 = true; //判断可输入的字段是否都为0；
          if (data.Iswidth) {
            if (!data.isEmptyWidth()) {
              isAll0 = false;
            }
            //宽
            var unit = baseUnit;
            _width = DecimalUtils.divide(_width, unit);
            if (_width == null || _width <= 0) {
              _width = 1; //fixme 小于等于0都当1处理
            }
          } else {
            _width = 1; //fixme 不可填写，就当1处理，不用参与计算
          }
          if (data.Isheight) {
            if (!data.isEmptyHeight()) {
              isAll0 = false;
            }
            //高
            var unit = baseUnit;
            _height = DecimalUtils.divide(_height, unit);
            if (_height == null || _height <= 0) {
              _height = 1; //fixme 小于等于0都当1处理
            }
          } else {
            _height = 1;
          }
          if (data.Islength) {
            if (!data.isEmptyLengths()) {
              isAll0 = false;
            }
            //长
            var unit = baseUnit;
            _lengths = DecimalUtils.divide(_lengths, unit);
            if (_lengths == null || _lengths <= 0) {
              _lengths = 1; //fixme 小于等于0都当1处理
            }
          } else {
            _lengths = 1;
          }
          // if (data.Isthickness && !data.isMT02()) {
          //厚；辅料的厚度不允许修改
          if (data.Isthickness) {
            if (!data.isEmptyThickness() && !data.isMT02()) {
              isAll0 = false; //辅料的厚度不允许修改，所以辅料不算。
            }
            //厚：辅料的厚度不允许修改，但是只要厚度打钩了，都需要参与计算。
            var unit = baseUnit;
            if (count <= 3) {
              //fixme 这里和pc计算方式同步一下；
              _thickness = DecimalUtils.divide(_thickness, unit);
            } else {
              //count大于等于4；就表示：宽，高，长，厚，用户都手动勾上了。但是erp上面的计算方式是，最大只能除以 3个1000；
              //所以第四个就不除以1000了。和erp保持一致。
            }
            if (_thickness == null || _thickness <= 0) {
              _thickness = 1; //fixme 小于等于0都当1处理
            }
          } else {
            _thickness = 1;
          }
          if (data.Isquantity) {
            if (!data.isEmptyNumbers()) {
              isAll0 = false;
            }
            if (_numbers <= 0) {
              _numbers = 1; //fixme 数量少于0，就当1计算。
            }
          } else {
            _numbers = 1;
          }
          if (isAll0) {
            //可输入的文本框，全部都是小于等于0；申请数量也为0
            data?.DemandNum = "0";
            data?.MinNum = "0";
          } else {
            //=============================
            //fixme 乘法：宽*高*长*厚度
            var num1 = DecimalUtils.multiply(_width, _height);
            // print("_width:$_width\t_height:$_height\tnum1:$num1");
            var num2 = DecimalUtils.multiply(_lengths, _thickness);
            // print("_lengths:$_lengths\_thickness:$_thickness\tnum2:$num2");
            var num3 = DecimalUtils.multiply(num1, num2);
            // print("num1:$num1\tnum2:$num2\tnum3:$num3");
            //fixme 除法：除以转化单位
            // print("num3:$num3\tn:$n");
            //var num4 = DecimalUtils.divide(num3, n.toDouble());//fixme 上面已经分别除过了，就不需要再统一除了。
            // print("num3:$num3\tn:$n\tnum4:$num4");
            //fixme 乘法：乘以数量
            // double? num5 = DecimalUtils.multiply(num4, _numbers);
            double? num5 = DecimalUtils.multiply(num3, _numbers);
            // print("num5:$num5");
            double applyNum = num5 ?? 0;
            if (applyNum <= 0) {
              data?.DemandNum = "0";
              data?.MinNum = "0";
            } else {
              //var s = applyNum.toString();
              var s = NumUtil.parse(applyNum);
              if (s.contains(".")) {
                //var applyNum2 = applyNum.toStringAsFixed(4);
                var applyNum2 = s; //直接显示完整的文本；不截取小数了。
                //print("申请数量手动计算：$applyNum\t$applyNum2");
                data?.DemandNum = applyNum2;
                data?.MinNum = applyNum2;
              } else {
                data?.DemandNum = s;
                data?.MinNum = s;
              }
            }
            //=============================
          }
        } catch (e) {
          print("申请数量计算异常：$e");
        }
      }
      //fixme 计算包数量
      if (isPackageCount) {
        data?.PackageCount = "1"; //包数量，自己赋值为1。
        data?.PackageListCount = data?.DemandNum; //每包数量，就赋值为申请数量。
      }
    }
  }

  /// 主数量；（自己赋值，与DemandNum一样即可）
  String? MinNum = "";

  /// 主单位
  String? MainUnit = "";

  /// 辅数量；(原片里面有(界面上显示的面积)，计算面积: Width*Height*DemandNum/ 1000000 )；只有原片有，辅料，五金没有。要自己手动计算；宽*高*申请数量
  String? SubsidiaryNum = "";

  ///计算辅数量（面积）;根据申请数量计算
  String? SubsidiaryNum2() {
    try {
      // var m = Width2() * Height2();
      // if (StringUtils.isNotEmpty(DemandNum)) {
      //   var m2 = double.parse(DemandNum!) * m / 1000000;
      //   //SubsidiaryNum = m2.toStringAsFixed(4);
      //   SubsidiaryNum = m2.toString();
      // }
      var m = Width2() * Height2();
      if (StringUtils.isNotEmpty(DemandNum)) {
        var m2 = double.parse(DemandNum!) * m / 1000000;
        //SubsidiaryNum = m2.toStringAsFixed(4);
        //SubsidiaryNum = m2.toString();
        //print("============================$SubsidiaryNum");
        //SubsidiaryNum = Decimal.parse(SubsidiaryNum!).toString();
        //print("$SubsidiaryNum");
        SubsidiaryNum = NumUtil.parse(m2);
      }
    } catch (e) {}
    if (StringUtils.isNotEmpty(SubsidiaryUnit)) {
      return "$SubsidiaryNum $SubsidiaryUnit";
    } else {
      return SubsidiaryNum;
    }
  }

  ///计算辅数量（面积）;根据批准数量计算
  String? SubsidiaryNum3() {
    try {
      // var m = Width2() * Height2();
      // if (StringUtils.isNotEmpty(DemandNum)) {
      //   var m2 = double.parse(DemandNum!) * m / 1000000;
      //   //SubsidiaryNum = m2.toStringAsFixed(4);
      //   SubsidiaryNum = m2.toString();
      // }
      var m = Width2() * Height2();
      if (StringUtils.isNotEmpty(ApproveNum)) {
        var m2 = double.parse(ApproveNum!) * m / 1000000;
        //SubsidiaryNum = m2.toStringAsFixed(4);
        //SubsidiaryNum = m2.toString();
        //print("============================$SubsidiaryNum");
        //SubsidiaryNum = Decimal.parse(SubsidiaryNum!).toString();
        //print("$SubsidiaryNum");
        SubsidiaryNum = NumUtil.parse(m2);
      }
    } catch (e) {}
    if (StringUtils.isNotEmpty(SubsidiaryUnit)) {
      return "$SubsidiaryNum $SubsidiaryUnit";
    } else {
      return SubsidiaryNum;
    }
  }

  ///是否显示辅数量（面积）
  bool isSubsidiaryNum() {
    /// 物料类型  MT01：原片 MT02：辅料 MT03：五金
    //String? MaterialType = "";
    if (MaterialType == MT01) {
      return true;
    }
    return false;
  }

  /// 辅单位
  String? SubsidiaryUnit = "";

  /// 品牌Id
  String? ManufacturerId = "";

  /// 品牌名称
  String? ManufacturerName = "";

  /// 库存主数量
  String? StockNum = "";

  String? StockNum2() {
    var _s = StringUtils.toStringAsDecimal(StockNum);
    if (StringUtils.isNotEmpty(MainUnit)) {
      return "$_s $MainUnit";
    }
    return _s;
  }

  /// 库存主面积；
  String? StockArea = "";

  /// 产品Id
  String? ProductId = "";

  ///来源类型
  String? SourceType = "";

  String? ApplyNum = ""; //原批准数量，服务器只会返回这两个之
  String? OriginApproveNum = ""; //原批准数量
  String? ApproveNum = ""; //批准数量
  @override
  fromJson(Map<String, dynamic> json) {
    ApplyNum = json["ApplyNum"]?.toString() ?? "";
    // print("=====================================================================ApplyNum:$ApplyNum");
    if (StringUtils.isEmpty(ApplyNum)) {
      ApplyNum = "0";
    }
    // print("=====================================================================ApplyNum:$ApplyNum");
    OriginApproveNum = json["MinNum"]?.toString() ?? "";
    ApproveNum = json["MinNum"]?.toString() ?? ""; //批准数量，默认值就是原批准数量
    ListId = json["ListId"]?.toString() ?? "";
    MaterialType = json["MaterialType"]?.toString() ?? "";
    MaterialTypeId = json["MaterialTypeId"]?.toString() ?? "";
    MaterialCode = json["MaterialCode"]?.toString() ?? "";
    MaterialName = json["MaterialName"]?.toString() ?? "";
    Width = json["Width"]?.toString() ?? "";
    Height = json["Height"]?.toString() ?? "";
    Thickness = json["Thickness"]?.toString() ?? "";
    Lengths = json["Lengths"]?.toString() ?? "";
    Numbers = json["Numbers"]?.toString() ?? "";
    var Isquantity2 = json["Isquantity"]?.toString().toLowerCase() ?? "";
    if (Isquantity2 == "true") {
      Isquantity = true;
    } else {
      Isquantity = false;
    }
    var Iswidth2 = json["Iswidth"]?.toString().toLowerCase() ?? "";
    if (Iswidth2 == "true") {
      Iswidth = true;
    } else {
      Iswidth = false;
    }
    var Isheight2 = json["Isheight"]?.toString().toLowerCase() ?? "";
    if (Isheight2 == "true") {
      Isheight = true;
    } else {
      Isheight = false;
    }
    var Isthickness2 = json["Isthickness"]?.toString().toLowerCase() ?? "";
    if (Isthickness2 == "true") {
      Isthickness = true;
    } else {
      Isthickness = false;
    }
    var Islength2 = json["Islength"]?.toString().toLowerCase() ?? "";
    if (Islength2 == "true") {
      Islength = true;
    } else {
      Islength = false;
    }
    var CanWrite2 = json["CanWrite"]?.toString().toLowerCase() ?? "";
    if (CanWrite2 == "true") {
      CanWrite = true;
    } else {
      CanWrite = false;
    }
    Size = json["Size"]?.toString() ?? "";
    DemandNum = json["DemandNum"]?.toString() ?? "";
    MinNum = json["MinNum"]?.toString() ?? "";
    MainUnit = json["MainUnit"]?.toString() ?? "";
    SubsidiaryNum = json["SubsidiaryNum"]?.toString() ?? "";
    SubsidiaryUnit = json["SubsidiaryUnit"]?.toString() ?? "";
    ManufacturerId = json["ManufacturerId"]?.toString() ?? "0";
    ManufacturerName = json["ManufacturerName"]?.toString() ?? "";
    StockNum = json["StockNum"]?.toString() ?? "";
    StockArea = json["StockArea"]?.toString() ?? "";
    ProductId = json["ProductId"]?.toString() ?? "0";
    SourceType = json["SourceType"]?.toString() ?? "";
    FactoryId = json["FactoryId"]?.toString() ?? "0";
    FactoryName = json["FactoryName"]?.toString() ?? "";
    MaterialTypeCode = json["MaterialTypeCode"]?.toString() ?? "";
    ListBeizhu = json["ListBeizhu"]?.toString() ?? "";
    PackageUnit = json["PackageUnit"]?.toString() ?? "";
    WidthUnit = json["WidthUnit"]?.toString() ?? "";
    HeightUnit = json["HeightUnit"]?.toString() ?? "";
    LengthUnit = json["LengthUnit"]?.toString() ?? "";
    ThicknessUnit = json["ThicknessUnit"]?.toString() ?? "";
    PackageCount = json["PackageCount"]?.toString() ?? "";
    PackageListCount = json["PackageListCount"]?.toString() ?? "";
    QuantityUnit = json["QuantityUnit"]?.toString() ?? "";
  }

  // bool isToMM = false; //fixme 提交的时候，单位是否转化为毫秒。
  @override
  Map<String, dynamic> toJson() {
    var map = <String, dynamic>{};
    map["ListId"] = ListId;
    map["MaterialType"] = MaterialType;
    map["MaterialTypeId"] = MaterialTypeId;
    map["MaterialCode"] = MaterialCode;
    map["MaterialName"] = MaterialName;

    map["Width"] = Width;
    map["Height"] = Height;
    map["Thickness"] = Thickness;
    map["Lengths"] = Lengths;
    // if (isToMM) {
    //   map["Width"] = AppUnitUtils.getRatWithMM2(WidthUnit, Width);
    //   map["Height"] = AppUnitUtils.getRatWithMM2(HeightUnit, Height);
    //   map["Thickness"] = AppUnitUtils.getRatWithMM2(ThicknessUnit, Thickness);
    //   map["Thickness"] = AppUnitUtils.getRatWithMM2(LengthUnit, Lengths);
    // }

    map["Numbers"] = Numbers;
    map["Isquantity"] = Isquantity;
    map["Iswidth"] = Iswidth;
    map["Isheight"] = Isheight;
    map["Isthickness"] = Isthickness;
    map["Islength"] = Islength;
    map["CanWrite"] = CanWrite;
    map["Size"] = Size;
    map["DemandNum"] = DemandNum;
    map["MinNum"] = MinNum;
    map["MainUnit"] = MainUnit;
    map["SubsidiaryNum"] = SubsidiaryNum;
    map["SubsidiaryUnit"] = SubsidiaryUnit;
    map["ManufacturerId"] = ManufacturerId;
    map["ManufacturerName"] = ManufacturerName;
    map["StockNum"] = StockNum;
    map["StockArea"] = StockArea;
    map["ProductId"] = ProductId;
    map["SourceType"] = SourceType;
    map["FactoryId"] = FactoryId;
    map["FactoryName"] = FactoryName;
    map["OriginApproveNum"] = OriginApproveNum;
    map["ApproveNum"] = ApproveNum;
    map["MaterialTypeCode"] = MaterialTypeCode;
    map["ListBeizhu"] = ListBeizhu;
    map["index"] = index;
    // print(
    //     "=====================================================================ApplyNum:$ApplyNum");
    map["ApplyNum"] = ApplyNum;
    if (StringUtils.isEmpty(ApplyNum)) {
      map["ApplyNum"] = "0"; //fixme 如果为空，物料请购会报数据格式错误。
    }
    map["PackageUnit"] = PackageUnit;
    map["WidthUnit"] = WidthUnit;
    map["HeightUnit"] = HeightUnit;
    map["LengthUnit"] = LengthUnit;
    map["ThicknessUnit"] = ThicknessUnit;
    map["PackageCount"] = PackageCount;
    map["PackageListCount"] = PackageListCount;
    map["QuantityUnit"] = QuantityUnit;
    return map;
  }

  ///自己定义的参数
// TextSelection? textSelection = null; //记录焦点位置
}

class WFLog extends BaseBean {
  /// 审核人
  String? PersonName = "";

  /// 备注
  String? Message = "";

  /// 审核时间
  String? InsertDatetime = "";

  /// 业务名称
  String? YwxName = "";
  String? YwxId = "";

  @override
  fromJson(Map<String, dynamic> json) {
    //print("进来了：\t$json");
    PersonName = json["PersonName"]?.toString() ?? "";
    Message = json["Message"]?.toString() ?? "";
    InsertDatetime = json["InsertDatetime"]?.toString() ?? "";
    YwxName = json["YwxName"]?.toString() ?? "";
    YwxId = json["YwxId"]?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return WFLog();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["PersonName"] = PersonName;
    map["Message"] = Message;
    map["InsertDatetime"] = InsertDatetime;
    map["YwxName"] = YwxName;
    map["YwxId"] = YwxId;
    return map;
  }
}

// {
// "Id": "358",
// "PurOrderCode": "POY2022100017",
// "PurCode": "PDY2022100020",
// "OrderType": "1",
// "SupplierName": "",
// "MaterialType": "MT01",
// "MaterialCode": "2134165001YP",
// "MaterialName": "5mmF绿",
// "ManufacturerName": "其他（初始化）",
// "CreaterName": "柳有波",
// "PurStartDate": "2022-10-18 0:00:00",
// "PurEndDate": "2022-10-18 0:00:00",
// "StatusName": "审核中",
// "YwxName": "采购审核(采购部经理)",
// "YwxId": "N8002-7",
// "wfId": "27984",
// "Page": "examine",
// "Status": "1",
// "SContractCode": "",
// "IsBind": "False",
// "ProjectName": "",
// "Size": "2134.0*1650.0",
// "PurOrderType": "大额采购",
// "IsChange": ""
// }
///采购单审核
class GetPurOrder extends PurContractBean {
  List<ContractCopyInfo>? PurOrderList = null;

  String? Id = "";
  String? PurOrderCode = ""; //采购单号
  String? PurCode = ""; //请购单号
  String? OrderType = "";
  String? SupplierName = ""; //供应商
  String? MaterialType = "";
  String? MaterialCode = "";
  String? MaterialName = "";
  String? ManufacturerName = "";
  String? CreaterName = "";
  String? PurStartDate = "";
  String? PurEndDate = "";
  String? StatusName = "";
  String? YwxName = "";
  String? YwxId = "";
  String? wfId = "";
  String? Page = "";
  String? Status = "";
  String? SContractCode = "";

  // String? IsBind = "";//fixme MaterialInfo 物料请购里有这个参数。
  String? ProjectName = "";
  String? Size = "";
  String? PurOrderType = "";
  String? IsChange = "";

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    super.fromJson(json); //fixme 先实现父类的
    Id = json["Id"]?.toString() ?? "";
    PurOrderCode = json["PurOrderCode"]?.toString() ?? "";
    PurCode = json["PurCode"]?.toString() ?? "";
    OrderType = json["OrderType"]?.toString() ?? "";
    SupplierName = json["SupplierName"]?.toString() ?? "";
    MaterialType = json["MaterialType"]?.toString() ?? "";
    MaterialCode = json["MaterialCode"]?.toString() ?? "";
    MaterialName = json["MaterialName"]?.toString() ?? "";
    ManufacturerName = json["ManufacturerName"]?.toString() ?? "";
    CreaterName = json["CreaterName"]?.toString() ?? "";
    PurStartDate = json["PurStartDate"]?.toString() ?? "";
    PurEndDate = json["PurEndDate"]?.toString() ?? "";
    StatusName = json["StatusName"]?.toString() ?? "";
    YwxName = json["YwxName"]?.toString() ?? "";
    YwxId = json["YwxId"]?.toString() ?? "";
    wfId = json["wfId"]?.toString() ?? "";
    Page = json["Page"]?.toString() ?? "";
    Status = json["Status"]?.toString() ?? "";
    SContractCode = json["SContractCode"]?.toString() ?? "";
    // IsBind = json["IsBind"]?.toString() ?? "";
    ProjectName = json["ProjectName"]?.toString() ?? "";
    Size = json["Size"]?.toString() ?? "";
    PurOrderType = json["PurOrderType"]?.toString() ?? "";
    IsChange = json["IsChange"]?.toString() ?? "";
    PurOrderList = setGenericFromJson(
        json, "PurOrderList", <ContractCopyInfo>[], ContractCopyInfo());
  }

  @override
  instance() {
    // TODO: implement instance
    return GetPurOrder();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    // var map = <String, dynamic>{};
    var map = super.toJson(); //fixme 先继承父类的
    map["Id"] = Id;
    map["PurOrderCode"] = PurOrderCode;
    map["PurCode"] = PurCode;
    map["OrderType"] = OrderType;
    map["SupplierName"] = SupplierName;
    map["MaterialType"] = MaterialType;
    map["MaterialCode"] = MaterialCode;
    map["MaterialName"] = MaterialName;
    map["ManufacturerName"] = ManufacturerName;
    map["CreaterName"] = CreaterName;
    map["PurStartDate"] = PurStartDate;
    map["PurEndDate"] = PurEndDate;
    map["StatusName"] = StatusName;
    map["YwxName"] = YwxName;
    map["YwxId"] = YwxId;
    map["wfId"] = wfId;
    map["Page"] = Page;
    map["Status"] = Status;
    map["SContractCode"] = SContractCode;
    // map["IsBind"] = IsBind;
    map["ProjectName"] = ProjectName;
    map["Size"] = Size;
    map["PurOrderType"] = PurOrderType;
    map["IsChange"] = IsChange;
    map["PurOrderList"] = PurOrderList;
    return map;
  }
}
